package com.mtons.mblog.modules.service.impl;

import com.alibaba.fastjson.TypeReference;
import com.mtons.mblog.base.utils.BeanUtils;
import com.mtons.mblog.modules.data.NavVo;
import com.mtons.mblog.modules.entity.Nav;
import com.mtons.mblog.modules.repository.NavRepository;
import com.mtons.mblog.modules.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * NavServiceImpl.
 * @author yuzhong
 * @date 2019/2/27 16:41
 */
@Service
public class NavServiceImpl implements NavService {
    @Autowired
    private NavRepository navRepository;

    @Override
    public Map<String, List<NavVo>> findNavsAll() {
        List<Nav> navs = navRepository.findAll();
        List<NavVo> navVoList = BeanUtils.copyProperties(navs, new TypeReference<List<NavVo>>() {
        });
        Map<String, List<NavVo>> stringListMap = navVoList.stream().collect(Collectors.groupingBy(NavVo::getTags));
        return stringListMap;
    }
}
